import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/home"
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/HomeView.vue')
  },
  {
    path: '/buy',
    name: 'buy',
    component: () => import('../views/BuyView.vue')
  },
  {
    path: '/sell',
    name: 'sell',
    component: () => import('../views/sellView.vue'),

  },

  //消息
  {
    path: '/news',
    name: 'news',
    component: () => import('../views/newsView.vue'),
    beforeEnter: (to, from, next) => {
      let token = window.localStorage.getItem("token");
      if (!token) {
        next("/sign");
        return;
      } else {
        next()
      }
    }
  },

  {
    path: '/user',
    name: 'user',
    component: () => import('../views/userView.vue'),
  },
  {
    path: '/Details',
    name: 'Details',
    component: () => import('../views/DetailsView.vue')
  },
  {
    path: '/seach',
    name: 'seach',
    component: () => import('../views/seachView.vue')
  },
  {
    path: '/trade',
    name: 'trade',
    component: () => import('../views/tradeView.vue')
  },
  {
    path: '/sign',
    name: 'sign',
    component: () => import('../views/SignView.vue')
  },
  {
    path: '/collection',
    name: 'collection',
    component: () => import('../views/CollectionView.vue')
  },
  {
    path: '/gobuy',
    name: 'gobuy',
    component: () => import('../views/goBuyView.vue'),
    beforeEnter: (to, from, next) => {
      let token = window.localStorage.getItem("token");
      if (!token) {
        next("/sign");
        return;
      } else {
        next()
      }
    }
  },
  {
    path: '/pay',
    name: 'pay',
    component: () => import('../views/payView.vue'),

  },
  {
    path: '/myorder',
    name: 'myorder',
    component: () => import('../views/myOrder.vue'),
    beforeEnter: (to, from, next) => {
      let token = window.localStorage.getItem("token");
      if (!token) {
        next("/sign");
        return;
      } else {
        next()
      }
    }
  },

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
